package com.ft.oa.enums;

/**
 * ResultCode class
 * 系统信息码值。成功码值、系统错误码值、业务型码值为三位数据，其它模块业务型数据共六位。
 * 每个模块前后加上注释标识出码值的开始和结束。枚举名称开头以模块名开头。
 * @author hefeng
 * @date 2021/12/30
 */
public enum ResultCode {
    /*********系统错误、通用业务错误、成功相关码值开始- 预留码值三位*********/
    SERVICE_OK(200,"成功"),
    SERVICE_NOT_LOGGED_IN(202,"未登录!"),
    SERVICE_NOT_FOUND(404,"访问的资源不存在!"),
    SERVICE_NOT_AUTH(405,"访问的资源无操作权限！"),
    SERVICE_NAME_REPEATED(601,"名称重复"),
    SERVICE_DELETE_ERR(602,"删除失败"),
    SERVICE_CREATE_ERR(603,"插入失败"),
    SERVICE_UPDATE_ERR(604,"修改失败"),
    SERVICE_NAME_REPEAT_ERR(605,"名称重复"),
    SERVICE_ERR(501,"服务异常"),
    HAVE_EXISTED(502,"同名节点已存在"),
    HAVE_MODIFIED(503,"数据已被修改"),
    HAS_CONCURRENCY(504,"存在并发操作"),
    SERVICE_CALL_ERROR(506,"服务不存在"),
    SERVICE_CONFIG_ERROR(507,"服务配置错误"),
    CHECK_REPEAT_ERROR(508,"校验重复提交异常"),
    CHECK_REPEAT_FAIL(509,"请勿重复提交"),
    SERVICE_CODE_ERROR(510,"服务响应码错误"),
    DATA_NOT_FOUND(511,"数据不存在"),
    DISABLE_AFTER_DELETE(512,"禁用之后再删除"),
    HAS_NO_DELETE_AUTH(513,"数据没有删除权限"),
    HAS_NO_UPDATE_AUTH(514,"数据没有修改权限"),
    HAS_NO_UPDATE_DEFE(515,"添加失败"),
    /*********系统错误、通用业务错误、成功相关码值结束*********/
    ;

    private String msg;

    private int code;
    /**携带数据*/
    private Object data;
    /**
     * msg参数
     */
    private String[] args;
    ResultCode(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    ResultCode(String msg, int code, Object data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public ResultCode setArgs(String ...args){
        this.args=args;
        return this;
    }
    public String[] getArgs(){
        return this.args;
    }
    public String getMsg() {
        return msg;
    }

    public ResultCode setData(Object data) {
        this.data = data;
        return this;
    }
    public ResultCode setMsg(String msg) {
        this.msg = msg;
        return this;
    }
    public static ResultCode getByCode(int code) {
        for (ResultCode value : ResultCode.values()) {
            if (value.code == code) {
                return value;
            }
        }
        return ResultCode.SERVICE_ERR;
    }

    public int getCode() {
        return code;
    }

    public Object getData() {
        return data;
    }
}
